package com.xuda.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xuda.eduservice.entity.EduCourse;
import com.xuda.eduservice.entity.EduTeacher;
import com.xuda.eduservice.service.EduCourseService;
import com.xuda.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：程序员徐大大
 * @description：TODO
 * @date ：2022-08-06 12:56
 */
@Service
public class EduTEacherAndCourse {
    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;

    @Cacheable(value = "course",key = "'IndexList'")//存放在缓存中
    public List<EduCourse> courseList(){
        //根据id进行降序排列，显示列表之后前8条热门课程记录
        QueryWrapper<EduCourse> wrapperCourse = new QueryWrapper<>();
        wrapperCourse.orderByDesc("id");
        wrapperCourse.last("limit 8");
        List<EduCourse> courseList = courseService.list(wrapperCourse);
        return courseList;
    }

    @Cacheable(value = "teacher",key = "'IndexList'")//存放在缓存中
    public  List<EduTeacher> teacherList() {
        //根据id进行降序排列，显示列表之后前4条讲师
        QueryWrapper<EduTeacher> wrapperTeacher = new QueryWrapper<>();
        wrapperTeacher.orderByDesc("id");
        wrapperTeacher.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(wrapperTeacher);
        return teacherList;
    }
}
